﻿@using Newtouch.Herp.Infrastructure.Enum
@{
    ViewBag.Title = "新增/修改";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    .formTitle span {
        color: red;
    }
    .tab-content #basicInfo table tr td {
        border: 0;
    }
    #tab li {
        padding: 2px 2px 0 2px;
    }
    #tab a {
        padding: 8px;
        width: 65px;
        text-align: center;
    }
</style>
<form id="form1">
    <div class="container" style="padding:0;">
        <ul class="nav nav-tabs" role="tablist" id="tab">
            <li role="presentation"><a href="#basicInfo" role="tab" data-toggle="tab" style="width: 80px;">基本信息</a></li>
            <li role="presentation"><a href="#department" role="tab" data-toggle="tab">科室</a></li>
            <li role="presentation"><a href="#staff" role="tab" data-toggle="tab">人员</a></li>
        </ul>
        <div class="tab-content" style="margin-top:10px;">
            <div id="basicInfo" role="tabpanel" class="tab-pane fade in active" style="padding-right:10px;">
                <table class="form">
                    <tr>
                        <th class="formTitle">上级：</th>
                        <td class="formValue">
                            <select id="parentId" name="parentId" class="form-control">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                        <th class="formTitle"><span class="required">*</span>名称：</th>
                        <td class="formValue">
                            <input id="name" name="name" type="text" class="form-control required" placeholder="请输入名称" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>首拼：</th>
                        <td class="formValue">
                            <input id="py" name="py" type="text" class="form-control" />
                        </td>
                        <th class="formTitle"><span class="required">*</span>等级：</th>
                        <td class="formValue">
                            @Html.DropDownList("level", EnumWarehouseLevel.OneLevel.ToDescSelectList(), "==请选择==", new { @class = "form-control form-an" })
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">排序：</th>
                        <td class="formValue">
                            <input id="px" name="px" type="text" class="form-control" placeholder="请输入排序" />
                        </td>
                        <th class="formTitle" style="height: 35px;">选项：</th>
                        <td class="formValue" style="padding-top: 1px;">
                            <div class="ckbox">
                                <input id="zt" name="zt" type="checkbox" checked="checked"><label for="zt">有效</label>
                            </div>
                            <div class="ckbox" style="margin-left:20px;">
                                <input id="isDefSyn" name="isDefSyn" type="checkbox"><label for="isDefSyn">默认同步</label>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">地址：</th>
                        <td class="formValue" colspan="3">
                            <textarea id="address" name="Icon" type="text" class="form-control" style="height: 30px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">备注：</th>
                        <td class="formValue" colspan="3">
                            <textarea id="remark" name="remark" type="text" class="form-control" style="height: 30px;"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div id="department" role="tabpanel" class="tab-pane fade in">
                <div id="departmentTree"></div>
            </div>
            <div id="staff" role="tabpanel" class="tab-pane fade in">
                <div id="staffTree"></div>
            </div>
        </div>
    </div>
</form>
<script lang="javascript">
    var keyWord = $.request("keyValue");
    $(function () {
        initControl();
        if (!!keyWord) {
            $.najax({
                url: "/WarehouseManage/Warehouse/GetFormJson",
                data: { keyWord: keyWord },
                dataType: "json",
                success: function (data) {
                    $("#form1").formSerialize(data);
                }
            });
        }
    });

    //初始化
    function initControl() {
        $("#parentId").bindSelect({
            url: "/WarehouseManage/Warehouse/GetPatientTreeSelectJson"
        });
        $('#tab a:first').tab('show');
        $("#departmentTree").treeview({
            height: 420,
            slimscroll: false,
            showcheck: true,
            url: "/WarehouseManage/Warehouse/GetDeptmentSelecotrTree?keyWord=" + keyWord
        });
        $("#staffTree").treeview({
            height: 420,
            slimscroll: false,
            showcheck: true,
            url: "/WarehouseManage/Warehouse/GetStaffSelecotrTree?keyWord=" + keyWord
        });
        $('#name').keyup(function () {
            $('#py').val($(this).toShouPin());
        });
    }

    //提交
    function AcceptClick(callback) {
        if (!DataValidate()) {
            return;
        }
        var postData = $("#form1").formSerialize();
        postData["departmentIds"] = String($("#departmentTree").getCheckedNodes());
        postData["staffghs"] = String($("#staffTree").getCheckedNodes());
        $.submitForm({
            url: "/WarehouseManage/Warehouse/SubmitForm?keyWord=" + keyWord,
            param: postData,
            success: function () {
                $.modalClose();
                callback();
            }
        });
    }

    //数据效验
    function DataValidate() {
        if ($("#name").val() === "") {
            $.modalAlert("库房名称必填", 'warning');
            return false;
        }
        if ($("#level").val() === "") {
            $.modalAlert("等级必选", 'warning');
            return false;
        }
        return true;
    }
        
</script>